package com.bt7274.exception;

import com.bt7274.enums.ResultCodeEnum;
import lombok.Getter;

/**
 * Business Exception
 *
 */
@Getter
public class BusinessException extends RuntimeException {

    /**
     * Error code
     */
    private final Integer code;

    /**
     * 异常处理
     */
    private final String message;

    /**
     * Constructor with ResultCodeEnum
     * @param resultCodeEnum Result code enum
     */
    public BusinessException(ResultCodeEnum resultCodeEnum) {
        super(resultCodeEnum.getMessage());
        this.code = resultCodeEnum.getCode();
        this.message = resultCodeEnum.getMessage();
    }

    /**
     * Constructor with custom code and message
     * @param code Custom code
     * @param message Custom message
     */
    public BusinessException(Integer code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }

    public BusinessException(String message) {
        super(message);
        this.code = ResultCodeEnum.ERROR.getCode();
        this.message = message;
    }

    public Integer getCode() {
        return code;
    }

    @Override
    public String getMessage() {
        return message;
    }
}